from Crypto.Cipher import AES
def splice(text):
    while len(text) % 16 != 0:
        text += b' '
    return text
def splice_key(key):
    while len(key) % 16 != 0:
        key += b' '
    return key
if __name__ == '__main__':
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect(('127.0.0.1', 8001))
    f = open(input("请输入文件名:"), "r+")
    f0 = f.readlines()
    f0 = ''.join(f0)
    text = f0
    text = text.encode()
    key = '20201303'
    aes = AES.new(splice_key(key), AES.MODE_ECB)
    encrypted_byte = aes.encrypt(splice(text))
    print("encrypted_byte: ", encrypted_byte)
    s.sendall(encrypted_byte)
    f.close()
    s.close()
import socket
from Crypto.Cipher import AES
def splice(text):
    while len(text) % 16 != 0:
        text += b' '
    return text
def splice_key(key):
    while len(key) % 16 != 0:
        key += b' '
    return key
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# s = socket.socket()
s.bind(('127.0.0.1', 8001))
s.listen()
conn, address = s.accept()
data = conn.recv(1024)
# print(data.decode())
key = '20201303'
aes = AES.new(splice_key(key), AES.MODE_ECB)
decrypt_byte = aes.decrypt(data)
decrypt_byte = decrypt_byte.decode()
name = input("解密后明文的文件名：")
f = open(name,"w+")
f.write("经服务器解密后的明文是:")
f.write(decrypt_byte)
f.close()
f = open(name,"r+")
f0 = f.readlines()
f0 = ''.join(f0)
print(f0)
f.close()
s.close()